//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by 罗李苏 on 16/5/20.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
     @objc convenience init(imageName: String?,target: AnyObject?, action: Selector,title: String? = nil) {
        self.init()
        
        
        let btn = UIButton()
        //设置图片
        if let ima = imageName{
            btn.setImage(UIImage(named: ima), forState: .Normal)
            btn.setImage(UIImage(named: ima + "_highlighted"), forState: .Highlighted)
        }
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        btn.setTitle(title, forState: .Normal)
        //设置颜色
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        //设置自适应大小
        btn.sizeToFit()
        
        //设置自定义视图
        self.customView = btn

    }
}